package com.example.netty.handler;

import com.example.netty.bean.DeviceMsg;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @Author : lichong
 * @description :
 * @Date Create in 20:46 2020/1/19
 * @Modified By : 消息体转换成bean
 **/
public class MessageBeanDecoder extends MessageToMessageDecoder<String> {
    private static final Logger logger = LoggerFactory.getLogger(MessageBeanDecoder.class);

    @Override
    protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
        logger.info("接收包体数据：{}", msg);
        //数据包转换成实体信息
        DeviceMsg info = new DeviceMsg(msg);
        out.add(info);
    }
}
